Today we're going to handle the condition where we have a blocked path.
So our eye guy starts down a path.
We computed our async and our path finding.
We have a path or going to the goal, boom, something happens, gets in the way.
Can we recover?
I thought that would be pretty useful.
Let's go ahead and get started.
All right.
So in order to handle a blocked path, we've got to create a blockage.
So I'm going to grab this wall right here.
I'll do a control D to duplicate.
Collisions are offset, duplicated in place.
I want to rotate that wall.
And let me move it in place.
That'll work.
Let's resize it.
Size or scale?
Nice and let's call it blockage so that we don't lose it.
And you could do this to your own maze.
And it doesn't have to be exactly the same, right?
As long as your dog can't get around it that way, it'll create a blockage.
I'm just going to add a part.
Let's see right here.
This is going to be my trigger.
So when he steps on this, I'll make it like I'll make it like, right here.
When he steps on this, the wall is going to pop up.
Right.
And we could make this trigger.
Now, it's not in the model.
That's all right.
I'm going to get my blockage right click, and then I'll group his model.
I'll call this.
I'll call the whole thing trigger.
And let's get our.
Part trigger.
Drag it into our model.
Trigger.
There we go.
We got our blockage in there, too.
Let's make sure that the trigger.
We want anchored on.
We can turn canned Clyde off.
So don't trip over it.
We can make it invisible, too.
I wouldn't make it fully invisible for testing, though.
Maybe, like, make it 0.7 or something just so we can see that it's there and you hit it.
All right, now I'm going to need a script.
This plus sign on trigger on the trigger model.
Add a script and we'll call this create block.
All right, Let's get rid of this print statement and we'll get a variable for our trigger.
The part we step on, trigger script, dot parent, and then down one level two trigger.
And then we also need a variable for the blockage.
So let me just call that wall.
There's only one wall we're worried about, and that's the blockage wall.
So I'll do script dot parent blockage.
Now we need to touch the vent for the trigger.
The trigger part right Trigger dot touched colon connect, and we'll just do an anonymous function right
here and we'll get the other part.
That's the part that hits the trigger.
We're going to check to see if it is an NPC or some sort of character.
Let's do local hume equals other part parent that would take it up to the character level.
And now we do a fine first child to see if there is a humanoid associated with that part that hit our
trigger.
If there is, let's go ahead and make a blockade.
So we'll do.
If HUME then hit our wall.
We'll set the transparency to zero and then we'll get the wall.
And that can collide to true.
Now Can collide is already true and transparency is already zero.
We need to change that.
We'll go ahead and copy this.
Control C, go up here, Control V and then we're just going to when the game starts up, we're going
to make this false, we're going to make that transparency one.
Now it's just like it's not even there.
Let's go ahead and play this.
He should run right into it.
We're just checking to see if our trigger works.
Let's go to view output, check for any errors.
See Slow dog.
He starts running.
He's like, I'll get that gold.
This is no problem.
Boom.
Oh bomber.
So he could the he did not handle the blocked path.
Now let's add the code to slaw dog to make it so that he can.
I'm going to turn my game off.
Here we go.
I close my walls.
I look for Slow Dog.
We call that move Npk.
Double click that.
And I'm going to get rid of this output window so I have a little more real estate.
So we've got our follow the path.
That's good.
Move to finish.
That's good down here.
I am going to get the path variable that we got, the path variable we got from create path on the path
winding and then going to do a dot blocked.
So a blocked is an event that's fired when the path is blocked.
So we get the blocked, we will connect that event when it gets fired to an anonymous function and we
get a waypoint right, we get a waypoint where the blockage occurs.
So I'll do WP for Waypoint and it will also fire a blocked event if the blockage happens behind us in
our track or behind the NPC.
So we don't care about that.
It can block behind us.
We only care about blocking in front of us, so we have to do an if statement we'll do if w p is greater
than the w p index, then we care, right?
So then what we're going to do is we're going to say a follow path
treasure.
And what that's going to do is call follow path.
Again, we're going to recompute new wave points, we're going to recover from our blockage and that
should do it.
Let's try.
Here we go.
Come on, Sardar.
Get that treasure.
Oh, look at that.
He figured it out.
Now he's going to go all the way around.
So I'm not going to I'm not going to make you watch all that, but you get the idea, he computed,
and he figured out how to get around.
That's pretty cool.
Next video I'm going to do climbing.